import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Home'
import User from '@/views/User'
import UserEdit from '@/views/User/UserEdit'
import Search from '@/views/Search'
import SearchResult from '@/views/Search/SearchResult'
import ArticleDetail from '@/views/ArticleDetail'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout' // 默认展示layout页面
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/layout',
    name: 'Layout',
    component: Layout,
    redirect: '/layout/home', // 马上在跳转二级路由显示
    children: [
      {
        path: 'home',
        component: Home
      },
      {
        path: 'user',
        component: User
      }
    ]
  },
  {
    path: '/search',
    component: Search
  },
  {
    // 动态路由: 路径上传值
    // 提前在规则里用/:变量名形式定义好
    // 要跳到当前路由路径上, 必须在第二段传值
    path: '/search/:keywords',
    component: SearchResult
  },
  {
    // 查询字符串(?)传参
    path: '/article',
    component: ArticleDetail
  },
  {
    path: '/user/edit',
    component: UserEdit
  }
]

const router = new VueRouter({
  routes
})

export default router
